package com.qijian.mold.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qijian.common.core.domain.AjaxResult;
import com.qijian.common.utils.poi.ExcelUtil;
import com.qijian.mold.domain.param.mold.CreateMoldParam;
import com.qijian.mold.domain.param.mold.SelectMoldParam;
import com.qijian.mold.domain.param.mold.UpdateMoldParam;
import com.qijian.mold.domain.param.moldChange.ConfirmMoldChangParam;
import com.qijian.mold.domain.param.moldChange.CreateMoldChangeParam;
import com.qijian.mold.domain.param.moldChange.SelectMoldChangeParam;
import com.qijian.mold.domain.param.moldChange.WorkshopConfirmMoldChangParam;
import com.qijian.mold.domain.param.task.CompleteMoldChangeParam;
import com.qijian.mold.domain.vo.ApiResultVo;
import com.qijian.mold.domain.vo.PageResult;
import com.qijian.mold.domain.vo.mold.MoldDetailsVo;
import com.qijian.mold.domain.vo.mold.MoldListVo;
import com.qijian.mold.domain.vo.moldChange.*;
import com.qijian.mold.service.MoldChangeService;
import com.qijian.mold.service.MoldChangeTaskService;
import com.qijian.mold.service.MoldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 模具仓库
 *
 * @author anni.zhu
 * @author anni.zhu@king-v.com
 * Created in 2025/3/29 19:38
 */
@Api(tags = "模具仓库")
@RestController
@RequestMapping("/mold")
public class MoldController {

    @Autowired
    private MoldService service;

    /**
     * 创建模具仓库
     *
     * @param param
     * @return
     */
    @PostMapping("/addMold")
    public ApiResultVo create(@RequestBody @Valid CreateMoldParam param) {
        service.create(param);
        return ApiResultVo.success();
    }

    /**
     * 修改模具仓库
     *
     * @param param
     * @return
     */
    @PostMapping("/updateMold")
    public ApiResultVo update(@RequestBody @Valid UpdateMoldParam param) {
        service.update(param);
        return ApiResultVo.success();
    }

    /**
     * 删除模具仓库
     *
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public ApiResultVo delete(@RequestParam("id") Long id) {
        service.delete(id);
        return ApiResultVo.success();
    }


    /**
     * 查看模具详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getMoldChange")
    public ApiResultVo<MoldDetailsVo> getTrainCourse(@RequestParam("id") Long id) {
        MoldDetailsVo vo = service.getById(id);
        return ApiResultVo.success(vo);
    }

    /**
     * 获取模具仓库分页列表
     *
     * @return
     */
    @PostMapping("/getMoldList")
    public PageResult<MoldListVo> getMoldChangeList(@RequestBody SelectMoldParam param) {
        Page<MoldListVo> page = service.selectByPage(param);
        return PageResult.success(page);
    }

    /**
     * 导入模具的模板
     *
     * @param response
     * @return
     */
    @GetMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response) {
        new ExcelUtil<>(CreateMoldParam.class).importTemplateExcel(response, "模具仓库导入模板");
    }

    /**
     * 导入模具仓库
     *
     * @param file
     */
    @PostMapping("/import")
    public void importMoldList(MultipartFile file) throws Exception {
        service.importMoldList(file);
    }
}
